clear all
set more off, perm
set maxvar 120000
set varabbrev off
* ---------------------------------------------- *
global dir 	"`1'"
global Data 	$dir/Data
global Tables 	$dir/Tables
global Figures 	$dir/Figures
global Work 	$dir/Work
global Temp 	$dir/Temp
global Pseudo	$dir/Work/Temp
* ---------------------------------------------- *
foreach PORTF in SIZE INV PROF MOME  {
use $Work/portfolio_`PORTF'_qnic, clear
tsset portf datem

gen cumQ=.
gen cumQMkt=.
	
eststo clear
foreach x of numlist 6  {
replace cumQ=cumQRetMo1	
eststo Mo1_`x': quietly: ivreg2 cumNRetMo1 cumQ if portf==`x', bw(1 ) robust   small

replace cumQ=cumQRetQr1	
eststo Qr1_`x': quietly: ivreg2 cumNRetQr1 cumQ if portf==`x', bw(4 ) robust small

replace cumQ=cumQRetYr1	
eststo Yr1_`x': quietly: ivreg2 cumNRetYr1 cumQ if portf==`x', bw(13)robust small

replace cumQ=cumQRetYr3	
eststo Yr3_`x': quietly: ivreg2 cumNRetYr3 cumQ if portf==`x', bw(37)robust small

replace cumQ=cumQRetYr5	
eststo Yr5_`x': quietly: ivreg2 cumNRetYr5 cumQ if portf==`x', bw(61)robust small
}
if "`PORTF'"=="SIZE" {
esttab Mo1_* Qr1_* Yr1_* Yr3_* Yr5_* using $Tables/Table07_June.csv,  nonotes compress b(4) se(4) star(c 0.10 b 0.05 a 0.01) nolabel nogap ar2 title(`PORTF') replace
	}
if "`PORTF'"!="SIZE" {
esttab Mo1_* Qr1_* Yr1_* Yr3_* Yr5_* using $Tables/Table07_June.csv,  nonotes compress b(4) se(4) star(c 0.10 b 0.05 a 0.01) nolabel nogap ar2 title(`PORTF') append
}
}
